package org.fu.crowd.controller;

import org.fu.crowd.service.api.ProjectProviderService;
import org.fu.crowd.utils.Common;
import org.fu.crowd.vo.DetailProjectVO;
import org.fu.crowd.vo.PortalTypeVO;
import org.fu.crowd.vo.ProjectVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class ProjectProviderController {

    @Resource
    private ProjectProviderService projectProviderService;


    /**
     * 保存projectVO
     * @param projectVO
     * @param memberId
     * @return
     */
    @RequestMapping("/save/projectVORemote")
    public Common<String> saveProjectVORemote(@RequestBody ProjectVO projectVO, @RequestParam("memberId") Integer memberId){
        try {
            projectProviderService.saveProject(projectVO,memberId);
            return Common.successWithoutData();
        }catch (Exception e){
            return Common.failed(e.getMessage());
        }
    }





    /**
     * 获取首页数据
     * @return
     */
    @RequestMapping("/get/portalTypeProjectData/remote")
    public Common<List<PortalTypeVO>> getPortalTypeProjectDataRemote(){
        try {
            List<PortalTypeVO> portalTypeVOS = projectProviderService.selectPortalTypeVOList();
            return Common.successWithoutData(portalTypeVOS);
        }catch (Exception e){
            e.printStackTrace();
            return Common.failed(e.getMessage());
        }
    }




    /**
     *  展示给前台的项目详情
     */
    @RequestMapping("/project/portal/showProjectDetail")
    public Common<DetailProjectVO> getPortalShowProjectDetail(@RequestParam("projectId")Integer projectId){
        try {
            DetailProjectVO detailProjectVO = projectProviderService.getDetailProjectVO(projectId);
            System.out.println(detailProjectVO);
            return Common.successWithoutData(detailProjectVO);
        }catch (Exception e){
            return Common.failed(e.getMessage());
        }
    }

}
